<template>
  <div>
      <van-nav-bar
        title="我的收藏"
        style="position:sticky;"
        left-arrow
        @click-left="$router.go(-1)"
      />
      <div>
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            :error.sync="error"
            error-text='请求失败，重新加载'
            @load="getfavorites"
            >
            <!-- <van-cell v-for="item in list" :key="item" :title="item.title" /> -->
            <ListItem v-for="(item,index) in list" :key="index" :articleData="item"></ListItem>
        </van-list>
      </div>
  </div>
</template>

<script>
import ListItem from '@/components/ListItem';
import {getuserfavorites} from '@/api/user'
export default {
    components: {
        ListItem,
    },
    data(){
        return {
            list: [],
            loading: false,
            finished: false,
            timestamp:null,
            error:false,
            page:1,
            per_page:10,
        }

    },
    methods:{
        async getfavorites(){
            let that=this;
            try{
                const {data} = await getuserfavorites({page:this.page,per_page:this.per_page})
                if(!data) return;
                console.log(data.data.results)
                const results=data.data.results
                if(data.message === 'OK'){
                    that.list=[...that.list,...results]
                }
                // 加在完成后将加载状态设为结束
                that.loading=false;
                //判断数据是否加载完成
                if(results.length<that.per_page){
                    return that.finished=true
                }else{
                    that.page+=1
                }
            }catch(err){
                console.log(err)
                this.loading=false
                this.error=true
            }
        },
    },
    created(){
    }
}
</script>

<style>

</style>